﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Model;
using Newtonsoft.Json;
using System.Configuration;
using Newtonsoft.Json.Linq;
using Model.ModelForJD;
using System.Web.Script.Serialization;
using Model.EntityModel;
using Aop.Api;
using Aop.Api.Request;
using Aop.Api.Response;
using Aop.Api.Domain;

namespace ThirdPartyInterface
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“Service1”。
    // 注意: 为了启动 WCF 测试客户端以测试此服务，请在解决方案资源管理器中选择 Service1.svc 或 Service1.svc.cs，然后开始调试。
    public class Service1 : IService1
    {
        public  readonly   string key = ConfigurationManager.AppSettings["Password"].ToString();
        private static double SumAmount = 0;
        private static double SumCreditCurrency = 0;
        private static double Money = 0;
        private static double CreditCurrency = 0;
        private static double CreateCurrency = 0;
        private JavaScriptSerializer jss = new JavaScriptSerializer();

        private double ShopSumAmount = 0;
        private double ShopSumCreditCurrency = 0;
        private string ids = "";

        //private double SumAmount = 0;
        //private double SumCreditCurrency = 0;
        //private double Money = 0;
        //private double CreditCurrency = 0;
        //private double CreateCurrency = 0;
        /// <summary>
        /// 获取Token
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public string GetToken(string userId, string pass)
        {
            Model.ViewModel.LoginModel model = new Model.ViewModel.LoginModel { Result = false, ResultMessage = "用户名或密码错误" };
            Model.EntityModel.User user = new Model.EntityModel.User();
            if (String.IsNullOrEmpty(userId))
            {
                return JsonConvert.SerializeObject(model);
            }
            if (String.IsNullOrEmpty(pass))
            {
                return JsonConvert.SerializeObject(model);
            }
            IData.IDAL<Model.EntityModel.User> dal = new Data.DAL<Model.EntityModel.User>();
            user = dal.Query(new Model.EntityModel.User(), string.Format("  Password='{0}' and  LoginName='{1}'",EncryptUtil.DesEncode(pass,key),userId));
            if (model == null)
            {
                return JsonConvert.SerializeObject(model);
            }
            model.userName = user.LoginName;
            model.pass = user.Password;
            model.tokenTime = DateTime.Now.ToLongDateString();
            model.Result = true;
            model.ResultMessage = "获取成功";
            return JsonConvert.SerializeObject(EncryptUtil.DesEncode(model, key));
        }

        /// <summary>
        /// 获取商品分类
        /// </summary>
        /// <param name="token">Token码</param>
        /// <returns></returns>

        public string GetGoodsTyoe(string token)
        {
            Model.ViewModel.GoodsTypeModel model = new Model.ViewModel.GoodsTypeModel { Result = false, ResultMessage = "Token码已失效,请重新获取" };
            try
            {
                if (String.IsNullOrEmpty(token.Trim()))
                {
                    return JsonConvert.SerializeObject(model);
                }
                Model.ViewModel.LoginModel login = JsonConvert.DeserializeObject<Model.ViewModel.LoginModel>(EncryptUtil.DesDecodeString(token, key));
                if (Convert.ToDateTime(login).AddMinutes(15) <= DateTime.Now)
                {
                    return JsonConvert.SerializeObject(model);
                }
                IData.IDAL<Model.EntityModel.GoodsClassification> dal = new Data.DAL<Model.EntityModel.GoodsClassification>();
                model.list = dal.QueryList(new Model.EntityModel.GoodsClassification(), " 1=1");
                model.Result = true;
                model.ResultMessage = "获取成功";
                return JsonConvert.SerializeObject(model);
            }
            catch (Exception)
            {
                return JsonConvert.SerializeObject(model);
            }
        }

        /// <summary>
        /// 获取商品
        /// </summary>
        /// <param name="token">Token码</param>
        /// <param name="typeId">商品分类ID</param>
        /// <returns></returns>
        public string GetGoods(string token,string typeId)
        {
            Model.ViewModel.GoodsModel model = new Model.ViewModel.GoodsModel { Result = false, ResultMessage = "Token码已失效,请重新获取" };
            try
            {
                if (String.IsNullOrEmpty(token.Trim()) || String.IsNullOrEmpty(typeId.Trim()))
                {
                    return JsonConvert.SerializeObject(model);
                }
                Model.ViewModel.LoginModel login = JsonConvert.DeserializeObject<Model.ViewModel.LoginModel>(EncryptUtil.DesDecodeString(token, key));
                if (Convert.ToDateTime(login).AddMinutes(15) <= DateTime.Now)
                {
                    return JsonConvert.SerializeObject(model);
                }
                IData.IDAL<Model.EntityModel.Goods> dal = new Data.DAL<Model.EntityModel.Goods>();
                model.list = dal.QueryList(new Model.EntityModel.Goods(), string.Format(" Classification_Id={0}",typeId));
                return JsonConvert.SerializeObject(model);
            }
            catch (Exception)
            {
                return JsonConvert.SerializeObject(model);
            }
        }
        #region 生成订单
        /// <summary>
        /// 生成订单 
        /// </summary>   
        /// <param name="ProvinceId">省id</param>
        /// <param name="CityId">市id</param>
        /// <param name="CountyId">县ID</param>
        /// <param name="CountrysideId">市ID</param>
        /// <param name="Address">详细地址</param>
        /// <param name="Name">姓名</param>
        /// <param name="Phone">手机</param>
        /// <param name="User_Id">用户ID</param>
        /// <param name="PayPassword">支付密码</param>
        /// <param name="InvoiceType">发票类型</param>
        /// <param name="GoodsParam">结算商品列表</param>
        /// <param name="InvoiceDetail"> 发票内容</param> 
        /// <param name="PayType">支付方式</param>
        /// <param name="goodsParam">商品集合</param>
        /// <param name="InvoiceDetail"></param>
        /// <param name="ZipCode"></param>
        /// <param name="AreaId"></param>
        /// <param name="WayType"></param>
        /// <returns></returns>
        public string MakeOrder(int ProvinceId, int CityId, int CountyId, int CountrysideId,string Address,string Name,string Phone,int User_Id,string PayPassword,int InvoiceType,int PayType, string goodsParam, string InvoiceDetail,string ZipCode,string AreaId,string WayType)
        {
            try
            {
                #region 验证参数
                if (ProvinceId <= 0 )
                {
                   //Common.GetInstance.JsonErrorMessage("ProvinceId未传");
                    return JsonErrorMessage("ProvinceId未传", "false"); ;
                }
                if ( CityId<=0)
                { 
                    return JsonErrorMessage("CityId未传", "false");
                }
                if (CountyId<=0)
                { 
                    return JsonErrorMessage("CountyId未传", "false");
                }
                if (CountrysideId<=0)
                { 
                    return JsonErrorMessage("CountrysideId未传", "false");
                }
                if (string.IsNullOrEmpty(Address))
                { 
                    return JsonErrorMessage("用户详细地址未传", "false");
                }
                if (string.IsNullOrEmpty(Name))
                {
                   // Common.GetInstance.JsonErrorMessage("用户姓名未传");
                    return JsonErrorMessage("用户姓名未传", "false");
                }
                if (string.IsNullOrEmpty(Phone))
                {
                    //Common.GetInstance.JsonErrorMessage("用户手机号未传");
                    return JsonErrorMessage("用户手机号未传", "false");
                }
                if (User_Id<=0)
                { 
                    return JsonErrorMessage("用户ID未传", "false");
                }
                if (InvoiceType<=0)
                { 
                    return JsonErrorMessage("发票类型未传", "false");
                }
                if (string.IsNullOrEmpty(PayPassword))
                { 
                    return JsonErrorMessage("支付密码未传", "false");
                }
                if (PayType<=0)
                { 
                    return JsonErrorMessage("支付方式未传", "false");
                }
                if (string.IsNullOrEmpty(goodsParam))
                { 
                    return JsonErrorMessage("商品集合未传", "false");
                }
                #endregion
                //验证支付密码是否正确
                IData.IDAL<Model.EntityModel.User> daluser = new Data.DAL<Model.EntityModel.User>();
                Model.EntityModel.User user = daluser.Query(" SELECT PayPassword FROM [User] WHERE ID=" + User_Id).FirstOrDefault();//BLL<User>.Creator("Select").Parameter(@"PayPassword", " AND ID=" + User_Id).FirstOrDefault<User>();
                if (user == null)
                {
                    //Common.GetInstance.JsonErrorMessage("该用户不存在");
                    return JsonErrorMessage("该用户不存在", "false");
                }
                if (string.IsNullOrEmpty(user.PayPassword))
                {
                    //Common.GetInstance.JsonErrorMessage("您未设置支付密码");
                    return JsonErrorMessage("您未设置支付密码", "false");
                }
                if (!Equals(user.PayPassword, EncryptUtil.DesEncode(PayPassword, ConfigurationManager.AppSettings["Password"])))
                {
                    //Common.GetInstance.JsonErrorMessage("支付密码不正确");
                    return JsonErrorMessage("支付密码不正确", "false");
                }
                //获取用户钱包余额
                IData.IDAL<Model.EntityModel.Wallet> dalWallet = new Data.DAL<Model.EntityModel.Wallet>();
                List<Model.EntityModel.Wallet> WalletList = dalWallet.Query("select SUM(CASE WHEN bin = 1 THEN Amount ELSE -Amount END) AS Amount,Type from [Wallet] where User_Id=" + User_Id + " GROUP BY Type ");
                    //BLL<Wallet>.Creator("Select").Parameter(@"SUM(CASE WHEN bin = 1 THEN Amount ELSE -Amount END) AS Amount,Type", " AND User_Id=" + User_Id + " GROUP BY Type");
                foreach (var item in WalletList)
                {
                    if (item.Type == 0)
                    {
                        Money = Convert.ToDouble(item.Amount);
                    }
                    if (item.Type == 1)
                    {
                        CreditCurrency = Convert.ToDouble(item.Amount);
                    }
                    if (item.Type == 2)
                    {
                        CreateCurrency = Convert.ToDouble(item.Amount);
                    }
                }
                //将商品json序列化为键值对格式 获取商品id集合并用“,”逗号分割
                Dictionary<string, object> GoodsParam = new Dictionary<string, object>();
                JArray obj = JsonConvert.DeserializeObject<JArray>(goodsParam);
                foreach (JObject item in obj)
                {
                    if (Equals(item["Goods_Id"], null))
                    {
                       // Common.GetInstance.JsonErrorMessage("没有商品ID");
                        return JsonErrorMessage("没有商品ID", "false");
                    }
                    if (Equals(item["Quantity"], null))
                    {
                       // Common.GetInstance.JsonErrorMessage("没有商品数量");
                        return JsonErrorMessage("没有商品数量", "false");
                    }
                    else
                    {
                        if (Convert.ToInt32(item["Quantity"]) == 0)
                        {
                            //Common.GetInstance.JsonErrorMessage("商品数量至少为一件");
                            return JsonErrorMessage("商品数量至少为一件", "false");
                        }
                    }
                    ids += item["Goods_Id"] + ",";
                    GoodsParam.Add(item["Goods_Id"].ToString(), item["Quantity"]);
                }
                if (ids.Length == 0)
                {
                    //Common.GetInstance.JsonErrorMessage("您没有要购买的商品");
                    return JsonErrorMessage("您没有要购买的商品", "false");
                }
                if (ids.Length > 0 && ids[ids.Length - 1] == ',')
                {
                    ids = ids.Substring(0, ids.Length - 1);
                }
                IData.IDAL<Model.EntityModel.Goods> dalGoods = new Data.DAL<Model.EntityModel.Goods>();
                List<Model.EntityModel.Goods> GoodsList = dalGoods.Query(" select * from Goods where AND Del_Flag=0 AND IsShelves=1 AND Status=1 AND ID IN (" + ids + ") ORDER BY Supplier_Id");
                //BLL<Goods>.Creator("Select").Parameter(@"*", " AND Del_Flag=0 AND IsShelves=1 AND Status=1 AND ID IN (" + ids + ") ORDER BY Supplier_Id");
                if (GoodsList.Count == 0)
                {
                    //Common.GetInstance.JsonErrorMessage("商品已下架或未通过审核");
                    return JsonErrorMessage("商品已下架或未通过审核", "false");
                }
                //判断库存
                foreach (var goods in GoodsList)
                {
                    if (goods.SupplierType == 1)
                    {
                        //商家为京东时判断库存
                        List<Dictionary<string, object>> skuNums = new List<Dictionary<string, object>>();
                        Dictionary<string, object> skuNum = new Dictionary<string, object>();
                        skuNum.Add("skuId", goods.Number);
                        skuNum.Add("num", Convert.ToInt32(GoodsParam[goods.ID.ToString()]));
                        skuNums.Add(skuNum);
                        InventoryForJD inventoryForJD = JsonConvert.DeserializeObject<InventoryForJD>(DataInteractForJD.GetInventoryForJD(JDUtil.GetJdToken().result.access_token, jss.Serialize(skuNums), AreaId));
                        if (inventoryForJD.result.Count == 0 || Convert.ToInt32(inventoryForJD.result[0].stockStateId) != 33)
                        {
                           // Common.GetInstance.JsonErrorMessage("商品" + goods.Name + "库存不足");
                            return JsonErrorMessage("商品" + goods.Name + "库存不足", "false");
                        }
                    }
                    else
                    {
                        if (goods.Quantity < Convert.ToInt32(GoodsParam[goods.ID.ToString()]))
                        {
                           // Common.GetInstance.JsonErrorMessage("商品" + goods.Name + "库存不足");
                            return JsonErrorMessage("商品" + goods.Name + "库存不足", "false");
                        }
                    }
                }
                //生成订单
                Model.EntityModel.Shop_Order shop_Order = new Model.EntityModel.Shop_Order();
                shop_Order.User_Id = User_Id;
                shop_Order.Type = 0;
                shop_Order.Number = DateTime.Now.ToString("yyyyMMddHHmmss") + Guid.NewGuid().ToString().Substring(0, 6);
                shop_Order.Consignee_Name = Name;
                shop_Order.Consignee_Phone = Phone;
                shop_Order.Consignee_ProvinceId = ProvinceId;
                shop_Order.Consignee_CityId = CityId;
                shop_Order.Consignee_CountyId = CountyId;
                shop_Order.Consignee_CountrysideId = CountrysideId;
                shop_Order.Consignee_Address = Address;
                shop_Order.Consignee_ZipCode = ZipCode;
                shop_Order.Status = 0;
                shop_Order.Supplier_Id = GoodsList[0].Supplier_Id;
                shop_Order.InvoiceType = Convert.ToInt32(InvoiceType);
                shop_Order.InvoiceDetail = InvoiceDetail;
                IData.IDAL<Model.EntityModel.Shop_Order> dalShopOrder = new Data.DAL<Model.EntityModel.Shop_Order>();
                dalShopOrder.AddData(shop_Order, "");//BLL<Shop_Order>.Creator("Insert").Parameter(shop_Order);
                string Shop_Ids = shop_Order.ID.ToString() + ",";
                long Supplier_Id = 0;
                //根据供应商不同进行拆单
                foreach (var goods in GoodsList)
                {
                    if (goods.Supplier_Id != Supplier_Id && Supplier_Id != 0)
                    {
                        ShopSumAmount = 0;
                        ShopSumCreditCurrency = 0;
                        shop_Order.Supplier_Id = goods.Supplier_Id;
                        shop_Order.Number = DateTime.Now.ToString("yyyyMMddHHmmss") + Guid.NewGuid().ToString().Substring(0, 6);
                        dalShopOrder.AddData(shop_Order,"");// BLL<Shop_Order>.Creator("Insert").Parameter(shop_Order);
                        Shop_Ids += shop_Order.ID.ToString() + ",";
                    }
                    Supplier_Id = goods.Supplier_Id;
                    AddShop_Order_Goods(shop_Order, goods, ShopSumAmount, ShopSumCreditCurrency, GoodsList, GoodsParam);
                }
                //获取京东判断库存的参数sku 删除购物车 并在生成订单后减库存
                List<string> sku = new List<string>();
                IData.IDAL<Model.EntityModel.ShoppingCart> dalShopCart = new Data.DAL<Model.EntityModel.ShoppingCart>();
                foreach (var item in GoodsList)
                {
                    ShoppingCart shoppingCart = dalShopCart.Query("select * from ShoppingCart where Del_Flag=0 AND User_Id=" + User_Id + " AND Goods_Id=" + item.ID).FirstOrDefault();
                        //BLL<ShoppingCart>.Creator("Select").Parameter(@"*", " AND Del_Flag=0 AND User_Id=" + User_Id + " AND Goods_Id=" + item.ID).FirstOrDefault<ShoppingCart>();
                    if (shoppingCart != null)
                    {
                        shoppingCart.Del_Flag = true;
                        //BLL<ShoppingCart>.Creator("Delete").Parameter(shoppingCart);
                        dalShopCart.DelData(shoppingCart, " ID="+shoppingCart.ID);
                    }
                    if (item.SupplierType == 1)
                    {
                        Dictionary<string, object> skugoods = new Dictionary<string, object>();
                        skugoods.Add("skuId", item.Number);
                        skugoods.Add("num", GoodsParam[item.ID.ToString()].ToString());
                        sku.Add(jss.Serialize(skugoods));
                    }
                    if (item.SupplierType != 1)
                    {
                        item.Quantity = item.Quantity - Convert.ToInt32(GoodsParam[item.ID.ToString()]);
                        item.SalesVolume += Convert.ToInt32(GoodsParam[item.ID.ToString()]);
                        dalGoods.EditData(item, "", " id=" + item.ID);//BLL<Goods>.Creator("UpdateQuantity").Parameter(item);
                    }
                }
                List<Shop_Order> Shop_OrderList = dalShopOrder.Query("select * from Shop_Order where Del_Flag=0 AND ID IN(" + Shop_Ids.Substring(0, Shop_Ids.Length - 1) + ")");
                //BLL<Shop_Order>.Creator("Select").Parameter(@"*", " AND Del_Flag=0 AND ID IN(" + Shop_Ids.Substring(0, Shop_Ids.Length - 1) + ")");
                if (Shop_OrderList.Count == 0)
                {
                    //Common.GetInstance.JsonErrorMessage("此订单不存在");
                    return JsonErrorMessage("此订单不存在", "false");
                }
                //总运费字段
                double SUMfreight = 0.00;
                IData.IDAL<Model.EntityModel.Shop_Order_Goods> dalShoporderGoods = new Data.DAL<Model.EntityModel.Shop_Order_Goods>();
                IData.IDAL<Model.EntityModel.PackageStrategy> dalPackAgest = new Data.DAL<Model.EntityModel.PackageStrategy>(); 
                //获取订单应付总额 和总运费
                foreach (var item in Shop_OrderList)
                {
                    double ExpressAmount = 0.00;
                    SumAmount += Convert.ToDouble(item.SumAmount);
                    SumCreditCurrency += Convert.ToDouble(item.SumCreditCurrency);
                    List<Shop_Order_Goods> shopOrderGoods = dalShoporderGoods.Query("SELECT * FROM View_Shop_Goods WHERE 1=1 AND Del_Flag=0 AND Shop_Order_Id=" + item.ID);
                    // BLL<Shop_Order_Goods>.Creator("SelectView").Parameter(@"*", " AND Del_Flag=0 AND Shop_Order_Id=" + item.ID);
                    foreach (var shopGoods in shopOrderGoods)
                    {
                        double Express = 0.00;
                        //当供应商为京东时查询运费
                        if (item.Supplier_Id == 2)
                        {
                            GetFreightForJD getFreightForJD = JsonConvert.DeserializeObject<GetFreightForJD>(DataInteractForJD.GetFreight(JDUtil.GetJdToken().result.access_token, sku, ProvinceId.ToString(), CityId.ToString(), CountyId.ToString(), CountrysideId.ToString(), "4"));
                            double freight = getFreightForJD.success ? getFreightForJD.result.freight : 0.00;
                            Express = freight;
                        }
                        else
                        {
                            //根据运费策略修改快递费        注:上线后过一段时间需修改为根据商家邮费策略变更
                            PackageStrategy packageStrategy = dalPackAgest.Query(" SELECT * FROM dbo.[PackageStrategy] WHERE 1=1 AND ID=" + shopGoods.PackageStrategy_Id).FirstOrDefault<PackageStrategy>();
                            // BLL<PackageStrategy>.Creator("Select").Parameter(@"*", " AND ID=" + shopGoods.PackageStrategy_Id).FirstOrDefault<PackageStrategy>();
                            if (packageStrategy != null)
                            {
                                if (packageStrategy.Type == 0)
                                {
                                    Express = 15;
                                }
                                else if (packageStrategy.Type == 1)
                                {
                                    Express = 0;
                                }
                                else if (packageStrategy.Type == 2)
                                {
                                    if (Convert.ToDouble(item.SumAmount) >= Convert.ToDouble(packageStrategy.Money))
                                    {
                                        Express = 0;
                                    }
                                    else
                                    {
                                        Express = Convert.ToDouble(packageStrategy.Money);
                                    }
                                }
                            }
                        }
                        //订单运费取最大值
                        if (ExpressAmount < Express)
                        {
                            ExpressAmount = Express;
                        }
                    }
                    SumAmount += ExpressAmount;
                    SUMfreight += ExpressAmount;
                    item.ExpressAmount = ExpressAmount + "";
                    dalShopOrder.EditData(item,""," id="+item.ID);//  BLL<Shop_Order>.Creator("UpdateExpressAmount").Parameter(item);
                }
                Dictionary<string, object> Countlist = new Dictionary<string, object>();
                Dictionary<string, object> Data = new Dictionary<string, object>();
                //支付方式为钱包余额
                if (PayType == 0)
                {
                    //判断钱包余额是否足够
                    if (Money < SumAmount || CreateCurrency + CreditCurrency < SumCreditCurrency)
                    {
                        //Common.GetInstance.JsonErrorMessage("您的钱包现金余额不足，请及时充值");
                        return JsonErrorMessage("您的钱包现金余额不足，请及时充值", "false");
                    }
                    string Number = "";
                    foreach (var shopOrder in Shop_OrderList)
                    {
                        Wallet wallet = new Wallet();
                        wallet.User_Id = shopOrder.User_Id;
                        wallet.BIn = false;
                        wallet.Abstract = 1;
                        if (CreditCurrency >= Convert.ToDouble(shopOrder.SumCreditCurrency))
                        {
                            wallet.Amount = shopOrder.SumCreditCurrency;
                            wallet.Type = 1;
                            //  BLL<Wallet>.Creator("Insert").Parameter(wallet);
                            dalWallet.AddData(wallet, "");
                            CreditCurrency = CreditCurrency - Convert.ToDouble(shopOrder.SumCreditCurrency);
                            shopOrder.SumCreditCurrency = wallet.Amount;
                            shopOrder.SumCKVoucher = "0";
                            // BLL<Shop_Order>.Creator("UpdateMoney").Parameter(shopOrder);
                            dalShopOrder.EditData(shopOrder, "", " ID=" + shopOrder.ID);
                        }
                        else
                        {
                            string SumCredit = shopOrder.SumCreditCurrency;
                            wallet.Amount = CreditCurrency.ToString();
                            wallet.Type = 1;
                            dalWallet.AddData(wallet, "");
                            //BLL<Wallet>.Creator("Insert").Parameter(wallet);
                            shopOrder.SumCreditCurrency = wallet.Amount;
                            wallet.Amount = (Convert.ToDouble(SumCredit) - CreditCurrency).ToString();
                            wallet.Type = 2;
                            dalWallet.AddData(wallet, "");// BLL<Wallet>.Creator("Insert").Parameter(wallet);
                            shopOrder.SumCKVoucher = wallet.Amount;
                            dalShopOrder.EditData(shopOrder, "", " ID=" + shopOrder.ID);// BLL<Shop_Order>.Creator("UpdateMoney").Parameter(shopOrder);
                            double Percentage = CreditCurrency / Convert.ToDouble(SumCredit);
                            CreditCurrency = CreditCurrency - CreditCurrency;

                            List<Shop_Order_Goods> Shop_Order_GoodsList = dalShoporderGoods.Query("select * from Shop_Order_Goods where Del_Flag=0 and ID=" + shopOrder.ID);

                            double Goods_SumCreditCurrency = 0;
                            foreach (var item in Shop_Order_GoodsList)
                            {
                                Goods_SumCreditCurrency = Convert.ToDouble(item.SumCreditCurrency);
                                item.SumCreditCurrency = (Percentage * Goods_SumCreditCurrency).ToString();
                                item.SumCKVoucher = (Goods_SumCreditCurrency - Convert.ToDouble(item.SumCreditCurrency)).ToString();
                                dalShoporderGoods.EditData(item, "", " ID=" + item.ID);// BLL<Shop_Order_Goods>.Creator("UpdateMoney").Parameter(item);
                            }
                        }
                        wallet.Amount = SumAmount + "";
                        wallet.Type = 0;
                        dalWallet.AddData(wallet, "");// BLL<Wallet>.Creator("Insert").Parameter(wallet);
                        if (shopOrder.Supplier_Id == 2)
                        {
                            shopOrder.Status = JDUtil.GetInstance.SubmitOrderForJD(shopOrder) ? 1 : -1;
                            //shopOrder.Status = 1;
                        }
                        else
                        {
                            shopOrder.Status = 1;
                        }
                        dalShopOrder.EditData(shopOrder, "", " ID=" + shopOrder.ID);
                        // BLL<Shop_Order>.Creator("UpdateStatusOfPay").Parameter(shopOrder);
                        Number += shopOrder.Number + ",";
                    }
                    Number = Number.Substring(0, Number.Length - 1);
                    Countlist.Add("Result", true);
                    Countlist.Add("Message", "支付成功");
                    Data.Add("Number", Number);
                    Data.Add("sHtmlText", "");
                    Countlist.Add("Data", Data);
                    return jss.Serialize(Countlist);
                }
                //支付方式为支付宝
                else if (PayType == 1)
                {
                    if (string.IsNullOrEmpty(WayType))
                    {
                        return JsonErrorMessage("访问类型未传", "false");
                    }
                    //判断置换券加创客券是否足够
                    if (CreateCurrency + CreditCurrency >= SumCreditCurrency)
                    {
                        string Number = "";
                        foreach (var Shop_Order in Shop_OrderList)
                        {
                            Wallet wallet = new Wallet();
                            wallet.User_Id = Shop_Order.User_Id;
                            wallet.BIn = false;
                            wallet.Abstract = 1;
                            if (CreditCurrency >= Convert.ToDouble(Shop_Order.SumCreditCurrency))
                            {
                                wallet.Amount = Shop_Order.SumCreditCurrency;
                                wallet.Type = 1;
                                dalWallet.AddData(wallet, "");
                                //BLL<Wallet>.Creator("Insert").Parameter(wallet);
                                CreditCurrency = CreditCurrency - Convert.ToDouble(Shop_Order.SumCreditCurrency);
                                Shop_Order.SumCreditCurrency = wallet.Amount;
                                Shop_Order.SumCKVoucher = "0";
                                dalShopOrder.EditData(Shop_Order, "", " ID=" + Shop_Order.ID);
                                //BLL<Shop_Order>.Creator("UpdateMoney").Parameter(Shop_Order);
                            }
                            else
                            {
                                string SumCredit = Shop_Order.SumCreditCurrency;
                                wallet.Amount = CreditCurrency.ToString();
                                wallet.Type = 1;
                                //BLL<Wallet>.Creator("Insert").Parameter(wallet);
                                dalWallet.AddData(wallet, "");
                                Shop_Order.SumCreditCurrency = wallet.Amount;
                                wallet.Amount = (Convert.ToDouble(SumCredit) - CreditCurrency).ToString();
                                wallet.Type = 2;
                                //BLL<Wallet>.Creator("Insert").Parameter(wallet);
                                dalWallet.AddData(wallet, "");
                                Shop_Order.SumCKVoucher = wallet.Amount;
                                //BLL<Shop_Order>.Creator("UpdateMoney").Parameter(Shop_Order);
                                dalShopOrder.EditData(Shop_Order, "", " ID=" + Shop_Order.ID);
                                double Percentage = CreditCurrency / Convert.ToDouble(SumCredit);
                                CreditCurrency = CreditCurrency - CreditCurrency;
                                StringBuilder select_Shop_Order_Goods = new StringBuilder();
                                select_Shop_Order_Goods.AppendFormat(" AND Shop_Order_Id = {0}", Shop_Order.ID);
                                select_Shop_Order_Goods.Append(" AND Del_Flag=0");
                                List<Shop_Order_Goods> Shop_Order_GoodsList = dalShoporderGoods.Query("SELECT * FROM Shop_Order_Goods WHERE 1=1 AND Del_Flag=0 AND Shop_Order_Id =" + Shop_Order.ID);// 
                                //BLL<Shop_Order_Goods>.Creator("Select").Parameter(@"*", select_Shop_Order_Goods.ToString());
                                double Goods_SumCreditCurrency = 0;
                                foreach (var item in Shop_Order_GoodsList)
                                {
                                    Goods_SumCreditCurrency = Convert.ToDouble(item.SumCreditCurrency);
                                    item.SumCreditCurrency = (Percentage * Goods_SumCreditCurrency).ToString();
                                    item.SumCKVoucher = (Goods_SumCreditCurrency - Convert.ToDouble(item.SumCreditCurrency)).ToString();
                                    dalShoporderGoods.EditData(item, "", " ID=" + item.ID); //BLL<Shop_Order_Goods>.Creator("UpdateMoney").Parameter(item);
                                }
                            }
                            Shop_Order.Status = -2;
                            //BLL<Shop_Order>.Creator("UpdateStatusOfPay").Parameter(Shop_Order);
                            dalShopOrder.EditData(Shop_Order, "", " ID=" + Shop_Order.ID);
                            PaymentRecord paymentRecord = new PaymentRecord();
                            paymentRecord.User_Id = Shop_Order.User_Id;
                            paymentRecord.Number = Shop_Order.Number;
                            paymentRecord.PayType = 0;
                            paymentRecord.ShopOrder_Id = Shop_Order.ID;
                            paymentRecord.Amount = SumAmount + "";
                            paymentRecord.Status = 0;

                            IData.IDAL<PaymentRecord> dalPayMRe = new Data.DAL<PaymentRecord>();
                            dalPayMRe.AddData(paymentRecord, "");// BLL<PaymentRecord>.Creator("Insert").Parameter(paymentRecord);
                            Number += Shop_Order.Number + ",";
                        }
                        Number = Number.Substring(0, Number.Length - 1);
                        if (WayType.Trim() == "0")
                        {
                            //把请求参数打包成数组
                            SortedDictionary<string, string> sParaTemp = AlipayUtil.GetSParaTemp();
                            sParaTemp.Add("return_url", Config.shop_return_url);
                            sParaTemp.Add("out_trade_no", Number);
                            sParaTemp.Add("subject", "含邮费" + SUMfreight + "元," + Shop_OrderList[0].Abstract);
                            sParaTemp.Add("total_fee", SumAmount + "");
                            sParaTemp.Add("body", "无忧商城");
                            //建立请求
                            string sHtmlText = '"' + Submit.BuildRequest(sParaTemp, "get", "确认") + '"';
                            Data.Add("sHtmlText", sHtmlText);
                        }
                        else
                        {
                            IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", Config.APPID, Config.rsa2_private_key, "json", "1.0", Config.rsa2_sign_type, Config.rsa2_alipay_public_key, Config.input_charset, false);
                            //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如：alipay.trade.app.pay
                            AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
                            request.SetNotifyUrl(Config.appnotify_url);
                            //SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
                            AlipayTradeAppPayModel alipayTradeAppPayModel = new AlipayTradeAppPayModel();
                            alipayTradeAppPayModel.Body = "无忧商城";
                            alipayTradeAppPayModel.Subject = "含邮费" + SUMfreight + "元," + Shop_OrderList[0].Abstract;
                            alipayTradeAppPayModel.TotalAmount = SumAmount + "";
                            alipayTradeAppPayModel.ProductCode = "QUICK_MSECURITY_PAY";
                            alipayTradeAppPayModel.OutTradeNo = Number;
                            alipayTradeAppPayModel.TimeoutExpress = "30m";
                            request.SetBizModel(alipayTradeAppPayModel);
                            //这里和普通的接口调用不同，使用的是sdkExecute
                            AlipayTradeAppPayResponse response = client.SdkExecute(request);
                            //HttpUtility.HtmlEncode是为了输出到页面时防止被浏览器将关键参数html转义，实际打印到日志以及http传输不会有这个问题
                            //res.Write(HttpUtility.HtmlEncode(response.Body));
                            //页面输出的response.Body就是orderString 可以直接给客户端请求，无需再做处理。
                            //string orderString = HttpUtility.HtmlEncode(response.Body);
                            string orderString = response.Body;
                            Data.Add("sHtmlText", orderString);
                        }
                        Data.Add("Number", Number);
                        Countlist.Add("Result", true);
                        Countlist.Add("Message", "获取成功");
                        Countlist.Add("Data", Data);
                        return jss.Serialize(Countlist);// JsonErrorMessage("访问类型未传", "false");
                    }
                    else
                    {
                        return JsonErrorMessage("您的钱包置换券余额不足，请及时充值", "false");
                    }
                }
                else
                { return JsonErrorMessage("支付方式参数不正确", "false"); }
            }
            catch (Exception ex)
            {
                //Common.GetInstance.JsonErrorMessage(ex.ToString());
                return JsonErrorMessage(ex.Message,"false");
            }
        }
        public void AddShop_Order_Goods(Shop_Order shop_Order, Goods goods, double Amount, double CreditCurrency, List<Goods> GoodsList, Dictionary<string, object> GoodsParam)
        {
            IData.IDAL<Shop_Order_Goods> dalShopGoods = new Data.DAL<Shop_Order_Goods>();
            IData.IDAL<Shop_Order> dalShopOrder = new Data.DAL<Shop_Order>();
            Shop_Order_Goods shop_Order_Goods = new Shop_Order_Goods();
            shop_Order_Goods.Shop_Order_Id = shop_Order.ID;
            shop_Order_Goods.Number = shop_Order.Number;
            shop_Order_Goods.Goods_Id = goods.ID;
            shop_Order_Goods.UnitPriceAmount = goods.Money;
            shop_Order_Goods.UnitPriceCreditCurrency = goods.CreditCurrency;
            shop_Order_Goods.SumAmount = (Convert.ToDouble(goods.Money) * Convert.ToDouble(GoodsParam[goods.ID.ToString()])).ToString();
            shop_Order_Goods.SumCreditCurrency = (Convert.ToDouble(goods.CreditCurrency) * Convert.ToDouble(GoodsParam[goods.ID.ToString()])).ToString();
            shop_Order_Goods.Quantity = Convert.ToInt32(GoodsParam[goods.ID.ToString()]);
            ShopSumAmount = Amount + Convert.ToDouble(shop_Order_Goods.SumAmount);
            ShopSumCreditCurrency = CreditCurrency + Convert.ToDouble(shop_Order_Goods.SumCreditCurrency);
            dalShopGoods.AddData(shop_Order_Goods,"");// BLL<Shop_Order_Goods>.Creator("Insert").Parameter(shop_Order_Goods);
            shop_Order.SumAmount = ShopSumAmount.ToString();
            shop_Order.SumCreditCurrency = ShopSumCreditCurrency.ToString();
            shop_Order.Abstract = GoodsList.Count > 0 ? GoodsList[0].Name + "等多件商品" : GoodsList[0].Name;
            //BLL<Shop_Order>.Creator("UpdateMoney").Parameter(shop_Order);
            dalShopOrder.AddData(shop_Order, "");
        }
        #endregion

        #region 支付宝支付接口
        /// <summary>
        /// 支付宝支付接口
        /// </summary>
        /// <param name="Shop_Id">订单ID</param>
        /// <param name="PayPassword">支付密码</param>
        /// <param name="PayType">支付方式（0平台购买 1支付宝购买）</param>
        /// <param name="WayType">访问类型（0是PC端1是移动端）</param>
        /// <returns></returns>
        public string Payments(long Shop_Id, string PayPassword, string PayType, string WayType)
        {
            try
            {
                if (Shop_Id <= 0)
                {
                    //  Common.GetInstance.JsonErrorMessage("订单ID未传");
                    return JsonErrorMessage("订单ID未传", "false");
                }
                if (string.IsNullOrEmpty(PayPassword))
                {
                    //Common.GetInstance.JsonErrorMessage("支付密码未传");
                    return JsonErrorMessage("支付密码未传", "false");
                }
                if (string.IsNullOrEmpty(PayType))
                {
                    return JsonErrorMessage("支付方式未传", "false");
                }
                SumAmount = 0;
                SumCreditCurrency = 0;
                Money = 0;
                CreditCurrency = 0;
                CreateCurrency = 0;
                Dictionary<string, object> Countlist = new Dictionary<string, object>();
                Dictionary<string, object> Data = new Dictionary<string, object>();
                #region 订单
                string strSql = " select * from Shop_Order where 1=1";
                strSql += " AND ID IN(" + Shop_Id + ") AND Del_Flag=0";
                IData.IDAL<Model.EntityModel.Shop_Order> dal = new Data.DAL<Model.EntityModel.Shop_Order>();
                List<Model.EntityModel.Shop_Order> Shop_OrderList = dal.Query(strSql);
                if (Shop_OrderList.Count == 0)
                {
                    return JsonErrorMessage("此订单不存在", "false");
                }
                #endregion

                #region 用户
                StringBuilder select_User = new StringBuilder();
                select_User.AppendFormat("select * from [User] where  ID={0}", Shop_OrderList[0].User_Id);
                IData.IDAL<Model.EntityModel.User> dalUser = new Data.DAL<Model.EntityModel.User>();
                List<Model.EntityModel.User> UserList = dalUser.Query(select_User.ToString());
                if (UserList.Count > 0)
                {
                    if (string.IsNullOrEmpty(UserList[0].PayPassword))
                    {
                        //Common.GetInstance.JsonErrorMessage("您未设置支付密码");
                        return JsonErrorMessage("您未设置支付密码", "false"); ;
                    }
                    if (!Equals(UserList[0].PayPassword, EncryptUtil.DesEncode(PayPassword, ConfigurationManager.AppSettings["Password"])))
                    {
                        //Common.GetInstance.JsonErrorMessage("支付密码不正确");
                        return JsonErrorMessage("支付密码不正确", "false");
                    }
                }
                else
                {
                    return JsonErrorMessage("该用户不存在", "false"); ;
                }
                #endregion

                StringBuilder select_Wallet = new StringBuilder();
                select_Wallet.AppendFormat("SELECT SUM(CASE WHEN bin = 1 THEN Amount ELSE -Amount END) AS Amount,Type FROM [Wallet] WHERE   User_Id={0} GROUP BY Type ", Shop_OrderList[0].User_Id);
                IData.IDAL<Model.EntityModel.Wallet> dalWallet = new Data.DAL<Model.EntityModel.Wallet>();
                List<Model.EntityModel.Wallet> WalletList = dalWallet.Query(select_Wallet.ToString());
                foreach (var item in WalletList)
                {
                    if (item.Type == 0)
                    {
                        Money = Convert.ToDouble(item.Amount);
                    }
                    if (item.Type == 1)
                    {
                        CreditCurrency = Convert.ToDouble(item.Amount);
                    }
                    if (item.Type == 2)
                    {
                        CreateCurrency = Convert.ToDouble(item.Amount);
                    }
                }
                foreach (var item in Shop_OrderList)
                {
                    SumAmount += Convert.ToDouble(item.SumAmount);
                    SumCreditCurrency += Convert.ToDouble(item.SumCreditCurrency);
                }
                if (Equals(PayType, "0"))
                {
                    if (Money >= SumAmount && CreateCurrency + CreditCurrency >= SumCreditCurrency)
                    {
                        string Number = "";
                        foreach (var Shop_Order in Shop_OrderList)
                        {
                            PayWallet(Shop_Order, CreditCurrency);
                            Model.EntityModel.Wallet wallet = new Model.EntityModel.Wallet();
                            wallet.User_Id = Shop_Order.User_Id;
                            wallet.BIn = false;
                            wallet.Abstract = 1;
                            wallet.Amount = SumAmount + "";
                            wallet.Type = 0;
                            dalWallet.AddData(wallet, "");// BLL<Wallet>.Creator("Insert").Parameter(wallet);
                            Shop_Order.Status = 1;
                            dal.EditData(Shop_Order, "", " id=" + Shop_Order.ID);// BLL<Shop_Order>.Creator("UpdateStatusOfPay").Parameter(Shop_Order);
                            Number += Shop_Order.Number + ",";
                        }
                        Number = Number.Substring(0, Number.Length - 1);
                        Countlist.Add("Result", true);
                        Countlist.Add("Message", "支付成功");
                        Data.Add("Number", Number);
                        Data.Add("sHtmlText", "");
                        Countlist.Add("Data", Data);
                        // res.Write(jss.Serialize(Countlist));
                        return JsonConvert.SerializeObject(Countlist);
                    }
                    else
                    {
                        return JsonErrorMessage("您的钱包现金余额不足，请及时充值", "false");
                    }
                }
                else if (Equals(PayType, "1"))
                {
                    if (string.IsNullOrEmpty(WayType))
                    {
                        // Common.GetInstance.JsonErrorMessage("访问类型未传");
                        return JsonErrorMessage("访问类型未传", "false"); ;
                    }
                    if (CreateCurrency + CreditCurrency >= SumCreditCurrency)
                    {
                        string Number = "";
                        foreach (var Shop_Order in Shop_OrderList)
                        {
                            PayWallet(Shop_Order, CreditCurrency);
                            Shop_Order.Status = -2;
                            dal.EditData(Shop_Order, "", " id=" + Shop_Order.ID);// BLL<Shop_Order>.Creator("UpdateStatusOfPay").Parameter(Shop_Order);
                            Model.EntityModel.PaymentRecord paymentRecord = new Model.EntityModel.PaymentRecord();
                            paymentRecord.User_Id = Shop_Order.User_Id;
                            paymentRecord.Number = Shop_Order.Number;
                            paymentRecord.PayType = 0;
                            paymentRecord.ShopOrder_Id = Shop_Order.ID;
                            paymentRecord.Amount = SumAmount + "";
                            paymentRecord.Status = 0;
                            IData.IDAL<Model.EntityModel.PaymentRecord> dalPaym = new Data.DAL<Model.EntityModel.PaymentRecord>();
                            dalPaym.AddData(paymentRecord, "");//BLL<PaymentRecord>.Creator("Insert").Parameter(paymentRecord);
                            Number += Shop_Order.Number + ",";
                        }
                        Number = Number.Substring(0, Number.Length - 1);
                        if (Equals(WayType, "0"))
                        {
                            //把请求参数打包成数组
                            SortedDictionary<string, string> sParaTemp = AlipayUtil.GetSParaTemp();
                            sParaTemp.Add("return_url", Config.shop_return_url);
                            sParaTemp.Add("out_trade_no", Number);
                            sParaTemp.Add("subject", Shop_OrderList[0].Abstract);
                            sParaTemp.Add("total_fee", SumAmount + "");
                            sParaTemp.Add("body", "无忧商城");
                            //建立请求
                            string sHtmlText = '"' + Submit.BuildRequest(sParaTemp, "get", "确认") + '"';
                            Data.Add("sHtmlText", sHtmlText);
                        }
                        else
                        {
                            IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", Config.APPID, Config.rsa2_private_key, "json", "1.0", Config.rsa2_sign_type, Config.rsa2_alipay_public_key, Config.input_charset, false);
                            //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称如：alipay.trade.app.pay
                            AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
                            request.SetNotifyUrl(Config.appnotify_url);
                            //SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
                            AlipayTradeAppPayModel alipayTradeAppPayModel = new AlipayTradeAppPayModel();
                            alipayTradeAppPayModel.Body = "无忧商城";
                            alipayTradeAppPayModel.Subject = Shop_OrderList[0].Abstract;
                            alipayTradeAppPayModel.TotalAmount = SumAmount + "";
                            alipayTradeAppPayModel.ProductCode = "QUICK_MSECURITY_PAY";
                            alipayTradeAppPayModel.OutTradeNo = Number;
                            alipayTradeAppPayModel.TimeoutExpress = "30m";
                            request.SetBizModel(alipayTradeAppPayModel);
                            //这里和普通的接口调用不同，使用的是sdkExecute
                            AlipayTradeAppPayResponse response = client.SdkExecute(request);
                            //HttpUtility.HtmlEncode是为了输出到页面时防止被浏览器将关键参数html转义，实际打印到日志以及http传输不会有这个问题
                            //res.Write(HttpUtility.HtmlEncode(response.Body));
                            //页面输出的response.Body就是orderString 可以直接给客户端请求，无需再做处理。
                            //string orderString = HttpUtility.HtmlEncode(response.Body);
                            string orderString = response.Body;
                            Data.Add("sHtmlText", orderString);
                        }
                        Data.Add("Number", Number);
                        Countlist.Add("Result", true);
                        Countlist.Add("Message", "获取成功");
                        Countlist.Add("Data", Data);
                        //res.Write(jss.Serialize(Countlist));
                        return JsonConvert.SerializeObject(Countlist);
                    }
                    else
                    {
                        return JsonErrorMessage("您的钱包置换券余额不足，请及时充值", "false");
                    }
                }
                else
                { return JsonErrorMessage("参数支付方式不正确", "false"); }
            }
            catch (Exception ex)
            {
                return JsonErrorMessage(ex.Message, "false");
            }
        }
        public static void PayWallet(Model.EntityModel.Shop_Order Shop_Order, double CreditCurrencyAmont)
        {
            Model.EntityModel.Wallet wallet = new Model.EntityModel.Wallet();
            wallet.User_Id = Shop_Order.User_Id;
            wallet.BIn = false;
            wallet.Abstract = 1;
            if (CreditCurrencyAmont >= Convert.ToDouble(Shop_Order.SumCreditCurrency))
            {
                wallet.Amount = Shop_Order.SumCreditCurrency;
                wallet.Type = 1;
                IData.IDAL<Model.EntityModel.Wallet> dalWallet = new Data.DAL<Model.EntityModel.Wallet>();
                dalWallet.AddData(wallet, "");
                //  BLL<Wallet>.Creator("Insert").Parameter(wallet);
                CreditCurrency = CreditCurrencyAmont - Convert.ToDouble(Shop_Order.SumCreditCurrency);
            }
            else
            {
                wallet.Amount = CreditCurrencyAmont.ToString();
                wallet.Type = 1;
                IData.IDAL<Model.EntityModel.Wallet> dalWallet = new Data.DAL<Model.EntityModel.Wallet>();
                dalWallet.AddData(wallet, "");
                //BLL<Wallet>.Creator("Insert").Parameter(wallet);
                wallet.Amount = (Convert.ToDouble(Shop_Order.SumCreditCurrency) - CreditCurrencyAmont).ToString();
                wallet.Type = 2;
                dalWallet.AddData(wallet, "");// BLL<Wallet>.Creator("Insert").Parameter(wallet);
                Shop_Order.SumCreditCurrency = CreditCurrencyAmont.ToString();
                Shop_Order.SumCKVoucher = (Convert.ToDouble(Shop_Order.SumCreditCurrency) - CreditCurrencyAmont).ToString();
                IData.IDAL<Model.EntityModel.Shop_Order> dalShopOrder = new Data.DAL<Model.EntityModel.Shop_Order>();
                dalShopOrder.EditData(Shop_Order,"","1=1 and id="+Shop_Order.ID);//  BLL<Shop_Order>.Creator("UpdateMoney").Parameter(Shop_Order);
                CreditCurrency = CreditCurrencyAmont - CreditCurrencyAmont;
                double Percentage = CreditCurrencyAmont / Convert.ToDouble(Shop_Order.SumCreditCurrency);

                #region Shop_Order_Goods
                IData.IDAL<Model.EntityModel.Shop_Order_Goods> dalShopOrderGood = new Data.DAL<Model.EntityModel.Shop_Order_Goods>();
                StringBuilder select_Shop_Order_Goods = new StringBuilder();
                select_Shop_Order_Goods.AppendFormat("select * from Shop_Order where 1=1 AND Shop_Order_Id = {0}", Shop_Order.ID);
                select_Shop_Order_Goods.Append(" AND Del_Flag=0");
                List<Model.EntityModel.Shop_Order_Goods> Shop_Order_GoodsList = dalShopOrderGood.Query( select_Shop_Order_Goods.ToString());
                double Goods_SumCreditCurrency = 0;
                foreach (var item in Shop_Order_GoodsList)
                {
                    Goods_SumCreditCurrency = Convert.ToDouble(item.SumCreditCurrency);
                    item.SumCreditCurrency = (Percentage * Goods_SumCreditCurrency).ToString();
                    item.SumCKVoucher = (Goods_SumCreditCurrency - Convert.ToDouble(item.SumCreditCurrency)).ToString();
                    dalShopOrderGood.EditData(item," ", " 1=1 and id=" + item.ID);
                }
                #endregion
            }
        }

        #endregion
        /// <summary>
        /// 返回提示信息
        /// </summary>
        /// <param name="exMessage"></param>
        /// <param name="isTrue"></param>
        /// <returns></returns>
        public string JsonErrorMessage(string exMessage, string isTrue)
        {
            return string.Format("{{\"Result\":" + isTrue + ",\"Message\":\"{0}\"}}", new System.Text.RegularExpressions.Regex("\\n|\\r|\\(|\\)| |\"|\\\\").Replace(exMessage, ""));
        }
    }
}
